/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package xsystems.GUI;

import java.io.File;
import java.util.ArrayList;
import org.jfree.chart.ChartPanel;
import xsystems.parserFile.MyUtility;
import xsystems.parserFile.ParserFileASC;
import xsystems.propagationModel.PropagationModel;
import xsystems.propagationModel.FreeSpaceModel;
import xsystems.propagationModel.HataModel;
import xsystems.propagationModel.ImportedModel;
import xsystems.propagationModel.LogDistanceModel;
import xsystems.propagationModel.Point;
import xsystems.propagationModel.TwoRaysModel;

/**
 *
 * @author Rafael Tosta
 */
public class Principal extends javax.swing.JFrame {

    private ArrayList<PropagationModel> modelList;
    private ChartPanel plotPanel;
    private String[] vetorModels = {"Free Space", "Log Distance", "Two Rays", "Hata"};

    /**
     * Creates new form Principal
     */
    public Principal() {
        initComponents();
        this.modelList = new ArrayList<>();

        showImportedFiles();
        showPropagationModels();
        recuperaParametros();
    }

    public void showImportedFiles() {
        String[] vetor = MyUtility.importFiles();
        jComboBoxImportedFiles.setModel(new javax.swing.DefaultComboBoxModel(vetor));

        if (vetor.length > 0) {
            jButtonEdit.setEnabled(true);
        } else {
            jButtonEdit.setEnabled(false);
        }

        this.modelList = new ArrayList<>();
        criaGrafico();
    }

    public void showPropagationModels() {
        jComboBoxPropagationModel.setModel(new javax.swing.DefaultComboBoxModel(vetorModels));
    }

    private void criaGrafico() {
        Plot p = new Plot();
        plotPanel = p.plotPanel(modelList);
        plotPanel.setSize(jPanelGrafico.getWidth(), jPanelGrafico.getHeight());
        plotPanel.setVisible(true);

        jPanelGrafico.removeAll();
        jPanelGrafico.add(plotPanel);
        jPanelGrafico.revalidate();
        jPanelGrafico.repaint();
    }

    // Verifica se já existe um modelo já plotado no gráfico
    // O obj do gráfico não permite legendas iguais, uma soluyçao seria identificar e alterar a legenda 
    private boolean testeShow(String n) {
        for (int i = 0; i < modelList.size(); i++) {
            if (n.replace(".tm", "").equals(modelList.get(i).getNomeMedodo())) {
                return false;
            }
        }
        return true;
    }

    public String getItemImportModel() {
        return (String) jComboBoxImportedFiles.getSelectedItem();
    }

    public String getItemModels() {
        return (String) jComboBoxPropagationModel.getSelectedItem();
    }

    public ImportedModel getImportModel() {
        return MyUtility.recuperaObjetoParser(getItemImportModel());
    }

    public String modeloParametros() {
        String arquivo = getItemModels();
        boolean selected = this.jCheckReceived.isSelected();
        String nome = "";

        if (vetorModels[1].equals(arquivo)) { //Log Distance
            return arquivo;
        }

        if (selected) {//potencia recebida
            nome = arquivo + " (Received Power)";
        } else {
            nome = arquivo + " (PathLoss)";
        }

        return nome;
    }

    //variaveis
    private int distTotal;
    private double PL_do;
    private double do_inicial;
    private int n_environment;

    private float Pt;
    private float Gt;
    private float Gr;
    private float Ht;
    private float Hr;

    private double frequency;
    private float L;

    // Hata:
    private int distancia;
    private float Hte;
    private float Hre;
    private float Fc;

    private final int QTD_PONTOS = 200;

    public void recuperaParametros() {
        String param = modeloParametros();
        ArrayList<String> lerParametros = MyUtility.lerParametros(param);
        String text = "";

        if (lerParametros == null) {
            jTextAreaParam.setText(text);
            return;
        }

        if (param.equals("Free Space (PathLoss)")) {
            text = "Total Distance: " + lerParametros.get(0) + " m \n"
                    + "Frequency: " + lerParametros.get(1) + " Hz";

            distTotal = Integer.parseInt(lerParametros.get(0));
            frequency = Float.parseFloat(lerParametros.get(1));

        }
        if (param.equals("Free Space (Received Power)")) {
            text = "Total Distance: " + lerParametros.get(0) + " m \n"
                    + "Pt: " + lerParametros.get(1) + " \n"
                    + "Gt: " + lerParametros.get(2) + " \n"
                    + "Gr: " + lerParametros.get(3) + " \n"
                    + "Frequency: " + lerParametros.get(4) + " \n"
                    + "L: " + lerParametros.get(5);

            distTotal = Integer.parseInt(lerParametros.get(0));
            Pt = Float.parseFloat(lerParametros.get(1));
            Gt = Float.parseFloat(lerParametros.get(2));
            Gr = Float.parseFloat(lerParametros.get(3));
            frequency = Float.parseFloat(lerParametros.get(4));
            L = Float.parseFloat(lerParametros.get(5));

        }

        if (param.equals("Hata (PathLoss)")) {
            text = "Total Distance: " + lerParametros.get(0) + " m \n"
                    + "Fc: " + lerParametros.get(1) + " \n"
                    + "Hte: " + lerParametros.get(2) + " \n"
                    + "Hre: " + lerParametros.get(3);

            distancia = Integer.parseInt(lerParametros.get(0));
            Fc = Float.parseFloat(lerParametros.get(1));
            Hte = Float.parseFloat(lerParametros.get(2));
            Hre = Float.parseFloat(lerParametros.get(3));

        }

        if (param.equals("Log Distance")) {
            text = "Total Distance: " + lerParametros.get(0) + " m \n"
                    + "PL_do: " + lerParametros.get(1) + " \n"
                    + "do_inicial: " + lerParametros.get(2) + " \n"
                    + "n_environment: " + lerParametros.get(3);

            distTotal = Integer.parseInt(lerParametros.get(0));
            PL_do = Float.parseFloat(lerParametros.get(1));
            do_inicial = Float.parseFloat(lerParametros.get(2));
            n_environment = Integer.parseInt(lerParametros.get(3));
        }

        if (param.equals("Two Rays (PathLoss)")) {
            text = "Total Distance: " + lerParametros.get(0) + " m \n"
                    + "Gt: " + lerParametros.get(1) + " \n"
                    + "Gr: " + lerParametros.get(2) + " \n"
                    + "Ht: " + lerParametros.get(3) + " \n"
                    + "Hr: " + lerParametros.get(4);

            distTotal = Integer.parseInt(lerParametros.get(0));
            Gt = Float.parseFloat(lerParametros.get(1));
            Gr = Float.parseFloat(lerParametros.get(2));
            Ht = Float.parseFloat(lerParametros.get(3));
            Hr = Float.parseFloat(lerParametros.get(4));

        }

        if (param.equals("Two Rays (Received Power)")) {
            text = "Total Distance: " + lerParametros.get(0) + " m \n"
                    + "Pt: " + lerParametros.get(1) + " \n"
                    + "Gt: " + lerParametros.get(2) + " \n"
                    + "Gr: " + lerParametros.get(3) + " \n"
                    + "Ht: " + lerParametros.get(4) + " \n"
                    + "Hr: " + lerParametros.get(5);

            distTotal = Integer.parseInt(lerParametros.get(0));
            Pt = Float.parseFloat(lerParametros.get(1));
            Gt = Float.parseFloat(lerParametros.get(2));
            Gr = Float.parseFloat(lerParametros.get(3));
            Ht = Float.parseFloat(lerParametros.get(4));
            Hr = Float.parseFloat(lerParametros.get(5));

        }
        jTextAreaParam.setText(text);
    }

    public void exportData() {
        File f = MyUtility.FileChooserSave(this);
        if (f != null) {            
            String arquivo = getItemImportModel();
            if (arquivo != null) {
                ImportedModel r = MyUtility.recuperaObjetoParser(arquivo);
                ArrayList<Point> p = r.getPoints();
                MyUtility.gravaData(f, r.getNomeMedodo(), p);

            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelConfig = new javax.swing.JPanel();
        jComboBoxImportedFiles = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jButtonEdit = new javax.swing.JButton();
        jButtonClean = new javax.swing.JButton();
        jButtonShowImported = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxPropagationModel = new javax.swing.JComboBox();
        jButtonShowModels = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jCheckReceived = new javax.swing.JCheckBox();
        jSeparator3 = new javax.swing.JSeparator();
        jButtonSetParameters = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaParam = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jPanelGrafico = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuImport = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        jMenuExit = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GPTEL Propagation Models");
        setMinimumSize(new java.awt.Dimension(835, 495));
        setName("framePrincipal"); // NOI18N
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        jPanelConfig.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings "));
        jPanelConfig.setMaximumSize(new java.awt.Dimension(700, 32767));
        jPanelConfig.setPreferredSize(new java.awt.Dimension(350, 500));

        jComboBoxImportedFiles.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel1.setText("Imported Files:");

        jButtonEdit.setText("Edit");
        jButtonEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditActionPerformed(evt);
            }
        });

        jButtonClean.setText("Clean");
        jButtonClean.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCleanActionPerformed(evt);
            }
        });

        jButtonShowImported.setText("Add model");
        jButtonShowImported.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonShowImportedActionPerformed(evt);
            }
        });

        jLabel2.setText("Propagation Model:");

        jComboBoxPropagationModel.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBoxPropagationModel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxPropagationModelActionPerformed(evt);
            }
        });

        jButtonShowModels.setText("Add model");
        jButtonShowModels.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonShowModelsActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Shruti", 1, 10)); // NOI18N
        jLabel3.setText("Desenvolved by Karine S. Almeida and Rafael T. Santos");

        jLabel5.setFont(new java.awt.Font("Shruti", 1, 10)); // NOI18N
        jLabel5.setText("GPTEL Coordinator: Edgar S. Júnior");

        jCheckReceived.setText("Received Power");
        jCheckReceived.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckReceivedActionPerformed(evt);
            }
        });

        jButtonSetParameters.setText("Set parameters");
        jButtonSetParameters.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSetParametersActionPerformed(evt);
            }
        });

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));

        jTextAreaParam.setEditable(false);
        jTextAreaParam.setColumns(20);
        jTextAreaParam.setRows(5);
        jTextAreaParam.setMaximumSize(new java.awt.Dimension(700, 32767));
        jTextAreaParam.setMinimumSize(new java.awt.Dimension(164, 94));
        jScrollPane1.setViewportView(jTextAreaParam);

        jButton1.setText("Export");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelConfigLayout = new javax.swing.GroupLayout(jPanelConfig);
        jPanelConfig.setLayout(jPanelConfigLayout);
        jPanelConfigLayout.setHorizontalGroup(
            jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelConfigLayout.createSequentialGroup()
                .addGroup(jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonClean)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 311, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jComboBoxPropagationModel, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jButtonShowModels))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jCheckReceived)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonSetParameters, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel1))
                    .addGroup(jPanelConfigLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonShowImported)
                            .addComponent(jComboBoxImportedFiles, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(14, 14, 14)
                        .addGroup(jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelConfigLayout.setVerticalGroup(
            jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelConfigLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxImportedFiles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonEdit))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonShowImported)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxPropagationModel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckReceived)
                    .addComponent(jButtonSetParameters))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonShowModels)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonClean)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        getContentPane().add(jPanelConfig);

        jPanelGrafico.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Gráfico", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout jPanelGraficoLayout = new javax.swing.GroupLayout(jPanelGrafico);
        jPanelGrafico.setLayout(jPanelGraficoLayout);
        jPanelGraficoLayout.setHorizontalGroup(
            jPanelGraficoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 518, Short.MAX_VALUE)
        );
        jPanelGraficoLayout.setVerticalGroup(
            jPanelGraficoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 510, Short.MAX_VALUE)
        );

        getContentPane().add(jPanelGrafico);

        jMenu1.setText("File");

        jMenuItem2.setText("New Model");
        jMenu1.add(jMenuItem2);
        jMenu1.add(jSeparator1);

        jMenuImport.setText("Import");
        jMenuImport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuImportActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuImport);

        jMenuItem4.setText("Export");
        jMenu1.add(jMenuItem4);
        jMenu1.add(jSeparator2);

        jMenuExit.setText("Exit");
        jMenuExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuExitActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuExit);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Tools");

        jMenuItem6.setText("Options");
        jMenu2.add(jMenuItem6);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("Help");

        jMenuItem5.setText("About");
        jMenu3.add(jMenuItem5);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Realiza uma opçao ao redimencionar a tela
     *
     * @param evt
     */
    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        jPanelGrafico.getComponent(0).setSize(jPanelGrafico.getWidth(), jPanelGrafico.getHeight());
    }//GEN-LAST:event_formComponentResized


    private void jMenuImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuImportActionPerformed
        File f = MyUtility.FileChooser(this);
        if (f != null) {
            ParserFileASC parser = new ParserFileASC(f.getPath(), this);
            parser.start();
        }
    }//GEN-LAST:event_jMenuImportActionPerformed

    private void jMenuExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuExitActionPerformed
        dispose();
    }//GEN-LAST:event_jMenuExitActionPerformed

    private void jButtonShowModelsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonShowModelsActionPerformed
        String arquivo = getItemModels();

        boolean selected = this.jCheckReceived.isSelected();

        if (arquivo != null) {
            if (vetorModels[0].equals(arquivo)) { //Free Space

                if (selected) {//potencia recebida

                    if (testeShow(vetorModels[0] + "(RP)")) {
                        FreeSpaceModel fs = new FreeSpaceModel(vetorModels[0] + "(RP)", distTotal, Pt, Gt, Gr, frequency, L, QTD_PONTOS);
                        System.out.println(vetorModels[0] + "(PL)");
                        System.out.println(distTotal);
                        System.out.println(frequency);
                        System.out.println(QTD_PONTOS);
                        this.modelList.add(fs);
                    }

                } else {

                    if (testeShow(vetorModels[0] + "(PL)")) {
                        FreeSpaceModel fs = new FreeSpaceModel(vetorModels[0] + "(PL)", distTotal, frequency, QTD_PONTOS);
                        this.modelList.add(fs);
                    }
                }
            }

            //obs: log distance só tem pathloss
            if (vetorModels[1].equals(arquivo)) { //Log Distance
                LogDistanceModel ld = new LogDistanceModel(arquivo, distTotal, PL_do, do_inicial, n_environment, QTD_PONTOS);
                this.modelList.add(ld);
            }

            if (vetorModels[2].equals(arquivo)) { //Two Rays
                if (selected) {//potencia recebida

                    if (testeShow(vetorModels[2] + "(RP)")) {
                        TwoRaysModel tr = new TwoRaysModel(vetorModels[2] + "(RP)", distTotal, Pt, Gt, Gr, Ht, Hr, QTD_PONTOS);
                        this.modelList.add(tr);
                    }

                } else {

                    if (testeShow(vetorModels[2] + "(PL)")) {
                        TwoRaysModel tr = new TwoRaysModel(vetorModels[2] + "(PL)", distTotal, Gt, Gr, Ht, Hr, QTD_PONTOS);
                        this.modelList.add(tr);
                    }

                }

            }

            if (vetorModels[3].equals(arquivo)) { //Hata
                if (selected) {//potencia recebida

                    if (testeShow(vetorModels[3] + "(RP)")) {
                        //Faça Nada
                    }

                } else {

                    if (testeShow(vetorModels[3] + "(PL)")) {

                        HataModel tr = new HataModel(vetorModels[3] + "(PL)", distancia, Fc, Hte, Hre, QTD_PONTOS);
                        this.modelList.add(tr);
                    }

                }

            }

            criaGrafico();
        }
    }//GEN-LAST:event_jButtonShowModelsActionPerformed

    private void jComboBoxPropagationModelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxPropagationModelActionPerformed

        String arquivo = getItemModels();
        //desativa o checkReceived
        if (arquivo.equals(vetorModels[1])) {
            this.jCheckReceived.setSelected(false);
            this.jCheckReceived.setEnabled(false);
        } else {
            this.jCheckReceived.setEnabled(true);
        }

        recuperaParametros();
    }//GEN-LAST:event_jComboBoxPropagationModelActionPerformed

    private void jButtonShowImportedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonShowImportedActionPerformed
        String arquivo = getItemImportModel();
        if (testeShow(arquivo) && arquivo != null) {
            ImportedModel recuperaObjetoParser = MyUtility.recuperaObjetoParser(arquivo);
            this.modelList.add(recuperaObjetoParser);
            criaGrafico();
        }
    }//GEN-LAST:event_jButtonShowImportedActionPerformed

    private void jButtonCleanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCleanActionPerformed
        this.modelList = new ArrayList<>();
        criaGrafico();
    }//GEN-LAST:event_jButtonCleanActionPerformed

    private void jButtonEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditActionPerformed
        EditImportedModel dialog = new EditImportedModel(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_jButtonEditActionPerformed

    private void jButtonSetParametersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSetParametersActionPerformed
        SetParameters dialog = new SetParameters(this, true);
        dialog.setVisible(true);
    }//GEN-LAST:event_jButtonSetParametersActionPerformed

    private void jCheckReceivedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckReceivedActionPerformed
        recuperaParametros();
    }//GEN-LAST:event_jCheckReceivedActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        exportData();
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonClean;
    private javax.swing.JButton jButtonEdit;
    private javax.swing.JButton jButtonSetParameters;
    private javax.swing.JButton jButtonShowImported;
    private javax.swing.JButton jButtonShowModels;
    private javax.swing.JCheckBox jCheckReceived;
    private javax.swing.JComboBox jComboBoxImportedFiles;
    private javax.swing.JComboBox jComboBoxPropagationModel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuExit;
    private javax.swing.JMenuItem jMenuImport;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JPanel jPanelConfig;
    private javax.swing.JPanel jPanelGrafico;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextArea jTextAreaParam;
    // End of variables declaration//GEN-END:variables
}
